Unit BDijitLayoutWidgetUnit;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils, BDijitWidgetUnit, BDojoSessionUnit;

Type

{ BDijitLayoutWidgetClass }

  //** Base class for a _Container widget which is responsible for laying out
  //** its children. Widgets which mixin this code must define layout() to
  //** manage placement and sizing of the children.

  BDijitLayoutWidgetClass = Class(BDijitWidgetClass)
  Private
    bIsLayoutContainer: Boolean;
    Procedure SetIsLayoutContainer(aValue: Boolean);
  Public
    //** Indicates that this widget is going to call resize() on its children
    //** widgets, setting their size, when they become visible.
    Property IsLayoutContainer: Boolean Read bIsLayoutContainer
      Write SetIsLayoutContainer;

    //** Inserts specified child widget's dom node as a child of this widget's
    //** container node, and possibly does other processing (such as layout).
    //** !!! Associated when add !!!
    Procedure AddChild(Const aWidget: BDijitWidgetClass);
    //**  Widgets override this method to size and position their
    //** contents/children. When this is called this._contentBox is guaranteed
    //** to be set (see resize()). This is called after startup(), and also
    //** when the widget's size has been changed.
    Procedure Layout;
    //** Change size mode: When changeSize is specified, changes the marginBox
    //** of this widget and forces it to relayout its contents accordingly.
    //** changeSize may specify height, width, or both. If resultSize is
    //** specified it indicates the size the widget will become after
    //** changeSize has been applied. Notification mode: When changeSize is
    //** null, indicates that the caller has already changed the size of the
    //** widget, or perhaps it changed because the browser window was resized.
    //** Tells widget to relayout its contents accordingly. If resultSize is
    //** also specified it indicates the size the widget has become. In either
    //** mode, this method also: 1. Sets this.borderBox and this.contentBox to
    //** the new size of the widget. Queries the current domNode size if
    //** necessary. 2. Calls layout() to resize contents (and maybe adjust
    //** child widgets).
    Procedure Resize(Const aWidth, aHeight, aTop, aLeft: Integer);
    //** Same shortcut
    Procedure Resize;
End;

Implementation

{ BDijitLayoutWidgetClass }

Procedure BDijitLayoutWidgetClass.SetIsLayoutContainer(aValue: Boolean);
Begin
  bIsLayoutContainer:=aValue;
  SetConfig('isLayoutContainer', aValue);
End;

Procedure BDijitLayoutWidgetClass.AddChild(Const aWidget: BDijitWidgetClass);
Begin
  Associate(aWidget);
  AddAjax('addChild(%s);', [aWidget.JSName]);
End;

Procedure BDijitLayoutWidgetClass.Layout;
Begin
  AddAjax('layout();');
End;

Procedure BDijitLayoutWidgetClass.Resize(Const aWidth, aHeight, aTop,
  aLeft: Integer);
Begin
  AddAjax('resize({w:%d,h:%d,t:%d,l:%d});', [aWidth, aHeight, aTop, aLeft]);
End;

Procedure BDijitLayoutWidgetClass.Resize;
Begin
  AddAjax('resize();');
End;

End.

